package com.google.samples.apps.paging

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.samples.apps.paging.adapter.GoodsPagingAdapter
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val postPagingAdapter = GoodsPagingAdapter()
        recyclerView.run {
            layoutManager = LinearLayoutManager(this@MainActivity)
            setHasFixedSize(true)
            adapter = postPagingAdapter
        }

        ViewModelProvider(this)
            .get(GoodsViewModel::class.java)
            .goodsPagedList.observe(this, Observer {
                postPagingAdapter.submitList(it)
            })
    }
}